import {Routes, Route, useRoutes, Navigate} from "react-router-dom";
import Home from "../pages/Home";
import News from "../pages/News";
import Message from "../pages/Message";
import Details from "../pages/Details";
import About from "../pages/About";

//3.导出一个匿名函数（匿名函数中可以使用钩子函数）
// export default function (){
//     return useRoutes([
//         {
//             path:'/home',
//             element:<Home/>,
//             children:[
//                 {
//                     path:'news',
//                     element:<News/>
//                 },{
//                     path: 'message',
//                     element: <Message/>,
//                     children:[
//                         {
//                             path:':id',
//                             element:<Details/>
//                         }
//                     ]
//                 },{
//                     index:true,
//                     element: <Navigate to={'message'}/>
//                 }
//             ]
//         },{
//             path:'/about',
//             element: <About/>
//         },{
//             path: '/',
//             element: <Navigate to={'/home'}/>
//         }
//     ])
// }


//4.导出一个自定义钩子函数
export default function useRouters(){
    return useRoutes([
        {
            path:'/home',
            element:<Home/>,
            children:[
                {
                    path:'news',
                    element:<News/>
                },{
                    path: 'message',
                    element: <Message/>,
                    children:[
                        {
                            path:':id',
                            element:<Details/>
                        }
                    ]
                },{
                    index:true,
                    element: <Navigate to={'message'}/>
                }
            ]
        },{
            path:'/about',
            element: <About/>
        },{
            path: '/',
            element: <Navigate to={'/home'}/>
        }
    ])
}